import axios from 'axios'
import { ElMessage } from 'element-plus'

let baseURL = ''
switch (import.meta.env.MODE) {
    case 'development':
        baseURL = 'http://127.0.0.1:4523/m1/2789260-0-default'
        break
    case 'production':
        baseURL = '/'
        break
}

const http = axios.create({
    baseURL,
})

http.interceptors.response.use(
    (res) => {
        if (res.status !== 200) {
            ElMessage.error('网络错误')
        }
        return res.data
    },
    (err) => {
        ElMessage.error('网络连接错误')
        return {
            success: false,
        }
    }
)

export default http
